<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>范例</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="v8js.resources.html">资源类型</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.v8js.html">V8Js</a></div>
 <div class="up"><a href="book.v8js.html">V8js</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="v8js.examples" class="chapter">
 <h1>范例</h1>

 <p class="para">
  Basic usage
 </p>
 <div class="example" id="example-4002">
  <p><strong>Example #1 Basic Javascript execution</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$v8&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">V8Js</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;basic.js&nbsp;*/<br /></span><span style="color: #0000BB">$JS&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;&nbsp;EOT<br /></span><span style="color: #DD0000">len&nbsp;=&nbsp;print('Hello'&nbsp;+&nbsp;'&nbsp;'&nbsp;+&nbsp;'World!'&nbsp;+&nbsp;"\\n");<br />len;<br /></span><span style="color: #007700">EOT;<br /><br />try&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$v8</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeString</span><span style="color: #007700">(</span><span style="color: #0000BB">$JS</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'basic.js'</span><span style="color: #007700">));<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">V8JsException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程会输出：</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
Hello World!
int(13)
</pre></div>
  </div>
 </div>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="v8js.resources.html">资源类型</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.v8js.html">V8Js</a></div>
 <div class="up"><a href="book.v8js.html">V8js</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
